package com.xgpro.mapper.archives;

import com.xgpro.domain.archives.dto.Patentt;
import com.xgpro.domain.archives.entity.Patent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface PatentMapper extends Mapper<Patent> {

    @Select("<script>" +
            " select id,name,license_time as licenseTime ,patent_type AS patentType ," +
            " patent_number as patentNumber ,patent_post AS patentPost,patent_person AS patentPerson,patent_internal_number AS patentInternalNumber,user_id as userId from t_patent" +
            "<where>" +
            " <if test=\"userId != null \"> " +
            "    user_id=#{userId}" +
            " </if>" +
            " <if test=\"type != null and type!='' or type==0 \"> " +
            "  and patent_type=#{type}  " +
            " </if>" +
            " <if test=\"name != null and name!='' \"> " +
            "  and name like CONCAT('%',#{name},'%')" +
            " </if>" +
            "</where>" +
            "</script>")
    List<Patentt> getPanentt(@Param("userId") Integer userId, @Param("name")String name, @Param("type")Integer type);

    @Delete("<script>" +
            " delete from t_patent where  id in " +
            " <foreach collection='list' index='index' item='id'  open='(' separator=',' close=')'> " +
            " #{id}" +
            " </foreach>" +
            " </script>")
    Integer batchDeletes(List<Integer> ids);


    @Delete("<script>" +
            " delete from t_patent where  user_id in " +
            " <foreach collection='list' index='index' item='id'  open='(' separator=',' close=')'> " +
            "  #{id}" +
            " </foreach>" +
            " </script>")
    Integer beletes(List<Integer> ids);
}
